<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>待办</title>
    <link href="Scripts/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="Scripts/bootstrap/css/font-awesome.css" rel="stylesheet"/>
 	<link href="Style/skin/css/style.css" rel="stylesheet" type="text/css" />
	<link href="Style/skin/css/animate.css" rel="stylesheet" type="text/css" />
	<link href="Style/skin/font/iconfont.css" rel="stylesheet" type="text/css" />
     <style type="text/css">
        .pagination
        {
            margin: 8px 0;
            display: block;
            font-size: 13px;
        }
        .pagination .controls
        {
            float: left;
            border: 0;
            padding: 7px 0 0 15px;
            color: #777;
        }
        .search-padding {
            padding-bottom: 1px;
        }
        .row {
            margin-right: -15px;
            margin-left: 0px;
        }
        .table {
            width: 100%;
            max-width: 100%;
            margin-bottom: 0px;
        }
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
	<div class="ibox-content">
        <div class="row search-padding">
			<div class="col-md-4 col-sm-4 pull-left">
				<div class="form-inline">
					<div class="form-group">
						<input type='text' placeholder="请输入关键词" id='TB_Key' class="form-control" style=" width:300px;" />
					</div>
					<button class="btn btn-success" type="button" onclick="javascript:SearchKey();"><i class="fa fa-search"></i> 查询</button>
				</div>
			</div>
		</div>	
		<table class="table  table-striped">
			<thead>
				<tr id="tablet">
				</tr>
			</thead>
			<tbody id="Table1"></tbody>
		</table>
		 <!-- 显示分页信息 -->
        <div class="row" style="text-align: left;">
            <ul class="pagination" id="page_nav">
            </ul>
            <ul class="pagination controls" id="page_info">
            </ul>
            <div style="clear: both;"></div>
        </div>
	</div>		
</div>
	<script language="JavaScript" src="Comm/JScript.js" type="text/javascript"></script>
    <script type="text/javascript" src="Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script src="Scripts/bootstrap/bootstrap-paginator/js/bootstrap-paginator.js" type="text/javascript"></script>
    <script src="Scripts/QueryString.js" type="text/javascript"></script>
    <script src="Scripts/config.js" type="text/javascript"></script>
    <script src="Comm/Gener.js" type="text/javascript"></script>
    <script src="Style/skin/layui/layer.js" type="text/javascript"></script>
    <script type="text/javascript">
    
        function GroupBarClick(groupName) {

				var alt = document.getElementById('Img' + groupName).alert;
				var sta = 'block';
				if(alt == 'Max') {
					sta = 'block';
					alt = 'Min';
					classname='fa fa-minus-square';
				} else {
					sta = 'none';
					alt = 'Max';
					classname='fa  fa-plus-square';
				}

				document.getElementById('Img' + groupName).className =classname;
				document.getElementById('Img' + groupName).alert = alt;

				var i = 0;
				for(i = 0; i <= 600; i++) {

					var row = document.getElementById(groupName + i);

					if(row == null || row == undefined || row.style == null)
						continue;

					if(sta == 'block') {
						row.style.display = '';
					} else {
						row.style.display = sta;
					}
				}
			}

			function WinOpenIt(url) {

			    window.open(url);
			    return;

            layer.open({
				  skin: 'layer-class',	
				  type: 2, 
				  title: '待办', 
				  area:['96%','90%'],
				  content: url
				}); 
            
        }

        var pageCount = 1;//总页数
        var pageSize = 10;//显示行数
        var total = 0;//总条数
        var pageIdx = 1;//当前页
        var pageStartN = 1; //开始行
        var realCount = 0; //页面的实际条数
        var groupNames = [];

        //页面启动函数.
        $(function () {
            InitPage();
            Paginator(pageCount, pageIdx);
        });

        function GetRuningData(pageIdex) {
            //获取参数，FlowNos，为空时显示所有的待办，否则显示参数中的流程
            var flowNos = GetQueryString("FlowNos");
            if (flowNos == null || flowNos == "" || flowNos == undefined)
                flowNos = null;
            //查询
            var TB_Key = $("#TB_Key").val();

            var handler = new HttpHandler("BP.WF.HttpHandler.WF");
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("Todolist_Init");

            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            data = eval('(' + data + ')');
            var sourceData;
            //获取在途总的查询信息

            realCount = data.length;
            if (flowNos != null) {
                realCount = 0;
                for (var i = 0; i < data.length; i++) {
                    if (flowNos.indexOf(data[i].FK_Flow) != -1)
                        realCount++; 
                }
            }

            //1.流程编号和查询组件为空时
            if (flowNos == null && TB_Key == "")
                sourceData = data;
            //2.流程编号不为空和查询组件为空时
            if (flowNos != null && TB_Key == "")
                sourceData = $.grep(data, function (n, i) {
                    return (flowNos.indexOf(data[i].FK_Flow) != -1);
                });
            //3.流程编号为空和查询组件不为空时
            if (flowNos == null && TB_Key != "")
                sourceData = $.grep(data, function (n, i) {
                    return (data[i].Title.indexOf(TB_Key) != -1);
                });
            //4.流程编号为不空和查询组件不为空时
            if (flowNos != null && TB_Key != "")
                sourceData = $.grep(data, function (n, i) {
                    return (flowNos.indexOf(data[i].FK_Flow) != -1) && (data[i].Title.indexOf(TB_Key) != -1);
                });

            //生成分组的字符串.
            //设置表头.
            var groupBy = GetQueryString("GroupBy");
            if (groupBy == "" || groupBy == null) groupBy = "ByFlow";
            var str = "";
            for (var i = 0; i < data.length; i++) {

                if (groupBy == "ByNode" || groupBy == "NodeName") {
                    if (str.indexOf('@' + data[i].NodeName + "@") == -1) {
                        if (flowNos == null || (flowNos != null && flowNos.indexOf(data[i].FK_Flow) != -1))
                            str += "@" + data[i].NodeName + "@";
                    }
                }

                if (groupBy == "ByFlow") {
                    if (str.indexOf('@' + data[i].FlowName + "@") == -1) {
                        if (flowNos == null || (flowNos != null && flowNos.indexOf(data[i].FK_Flow) != -1))
                            str += "@" + data[i].FlowName + "@";
                    }

                }

                if (groupBy == "ByStarter") {
                    if (str.indexOf('@' + data[i].StarterName + "@") == -1) {
                        if (flowNos == null || (flowNos != null && flowNos.indexOf(data[i].FK_Flow) != -1))
                            str += "@" + data[i].StarterName + "@";
                    }
                }
            }
            groupNames = str.split("@"); //生成数组.



            //总数
            total = sourceData.length;
            //获取分页的数据信息
            data = [];
            pageStartN = (pageIdex - 1) < 0 ? 1 : (pageIdx - 1) * pageSize;
            pageEndN = pageIdx * pageSize > total ? total : pageIdx * pageSize;
            for (var i = pageStartN; i < pageEndN; i++) {
                data.push(sourceData[i]);
            }

            //总页数
            if (total % pageSize != 0)
                pageCount = parseInt(total / pageSize) + 1;
            else
                pageCount = parseInt(total / pageSize);
            if (pageCount == 0) pageCount = 1;

            return data;

        }

        //初始化数据.
        var showGroup = "";
        function InitPage() {
             var flowNos = GetQueryString("FlowNos");
            //获取当前时间
            var cdt = getNowFormatDate();
            var timeKey = Math.random();

            var data = GetRuningData(pageIdx);

            //设置表头.
            var groupBy = GetQueryString("GroupBy");
            if (groupBy == "" || groupBy == null)  groupBy = "ByFlow";

            var nodeIDt = GetQueryString("FK_Node");

            var tablet = "";
            tablet += "<th style='width:40px;'>序</th>";
            // title += "<th >优先级</th>";
            tablet += "<th>标题</th>";

            if (groupBy == "ByNode") {
                tablet += "<th><a href='?FK_Node=" + nodeIDt + "&GroupBy=ByFlow' >流程</th>";
                tablet += "<th><a href='?FK_Node=" + nodeIDt + "&GroupBy=ByStarter' >发起人</th>";
            }

            if (groupBy == "ByFlow") {
                tablet += "<th><a href='?FK_Node=" + nodeIDt + "&GroupBy=ByNode' >节点</th>";
                tablet += "<th><a href='?FK_Node=" + nodeIDt + "&GroupBy=ByStarter' >发起人</th>";
            }

            if (groupBy == "ByStarter") {
                tablet += "<th><a href='?FK_Node=" + nodeIDt + "&GroupBy=ByFlow' >流程</th>";
                tablet += "<th><a href='?FK_Node=" + nodeIDt + "&GroupBy=ByNode' >节点</th>";
            }

            tablet += "<th>发起日期</th>";
            tablet += "<th>到达</th>";
            tablet += "<th>期限</th>";
            tablet += "<th>状态</th>";
            tablet += "<th>类型</th>";

            $("#tablet").html(tablet);

           
          

            //生成分组的字符串.
            var str = "";
            var num = pageStartN;
            var is1 = false;
            $('#Table1').html("");

             //循环数组.
            for (var idx = 0; idx < groupNames.length; idx++) {
                var showRealCount = 0;
                var listbox = '';
                var groupName = groupNames[idx];

                if (groupName == "" || groupName == null)
                    continue;

                listbox+="<tr  onclick=\"GroupBarClick('" + groupName + "')\" > <th colspan=9 class='table-title'> <i class='fa fa-minus-square' alert='Min'  id='Img" + groupName + "'></i><span>" + groupName + "</span></th> </tr>";
            //增加处理.
                for (var i = 0; i < data.length; i++) {
                    var work = data[i];
                    if (groupBy == "ByNode" || groupBy == "NodeName") {
                        if (work.NodeName != groupName) {
                            continue;
                        }
                    } else if (groupBy == "ByFlow") {
                        if (work.FlowName != groupName) {
                            continue;
                        }
                    } else if (groupBy == "ByStarter") {
                        if (work.StarterName != groupName) {
                            continue;
                        }
                    } else {
                        continue;
                    }

                    //当参数flowNos不为空时，流程编码存在于flowNos时显示
                    if (flowNos != null && flowNos.indexOf(data[i].FK_Flow) == -1)
                        continue;

                    num++;
                    showRealCount++;
                    var newRow = "";
                    var title = work.Title;
                    var isRead = work.IsRead;
                    var flowNo = work.FK_Flow;
                    var flowName = work.FlowName;
                    var nodeName = work.NodeName;
                    var starterName = work.StarterName;
                    var pri = work.PRI;
                    var nodeID = work.FK_Node;
                    var fid = work.FID;
                    var workID = work.WorkID;
                    var pWorkID = work.PWorkID;
                    var paras = work.AtPara;

                    if (paras) {

                        paras = paras.replace("'", "\\'");

                        while (true) {
                            paras = paras.replace('@', '&');

                            if (paras.indexOf('@') < 0) {
                                break;
                            }
                        }
                        paras = "1" + paras;
                    }



                    if (is1 == true) {
                        listbox += "<tr  id='" + groupName + num + "' >";
                        is1 = false;
                    }
                    else {
                        listbox += "<tr   id='" + groupName + num + "' >";
                        is1 = true;
                    }
                    listbox += "<td>" + num + "</td>"; //序号.

                    var url = "";
                    if (isRead == 0)
                        url = "<a href=\"javascript:WinOpenIt('MyFlow.htm?FK_Flow=" + flowNo + "&PWorkID=" + pWorkID + "&FK_Node=" + nodeID + "&FID=" + fid + "&WorkID=" + workID + "&IsRead=0&T=" + timeKey + "&Paras=" + paras + "');\" ><img class=Icon align='middle'  src='Img/Mail_UnRead.png' />" + title + "</a>";
                    else
                        url = "<a href=\"javascript:WinOpenIt('MyFlow.htm?FK_Flow=" + flowNo + "&PWorkID=" + pWorkID + "&FK_Node=" + nodeID + "&FID=" + fid + "&WorkID=" + workID + "&IsRead=0&T=" + timeKey + "&Paras=" + paras + "');\" ><img class=Icon align='middle'  src='Img/Mail_Read.png' />" + title + "</a>";

                    listbox += "<td>" + url + "</td>"; //标题

                    if (groupBy == "ByNode" || groupBy == "NodeName") {
                        listbox += "<td>" + flowName + "</td>"; //流程类别
                        listbox += "<td>" + starterName + "</td>"; //发起人
                    } else if (groupBy == "ByFlow") {
                        listbox += "<td>" + nodeName + "</td>"; //节点名称
                        listbox += "<td>" + starterName + "</td>"; //发起人

                    } else if (groupBy == "ByStarter") {
                        listbox += "<td>" + flowName + "</td>"; //流程类别
                        listbox += "<td>" + nodeName + "</td>"; //节点名称
                    }


                    listbox += "<td>" + work.RDT + "</td>"; //发起时间
                    listbox += "<td>" + work.ADT + "</td>"; //接受时间
                    listbox += "<td>" + work.SDT + "</td>"; //应完成时间

                    //为天业解决开始节点撤销回来后，就是逾期状态.
                    var len = nodeID.toString().length;
                    var entStr = nodeID.toString().substr(len - 2);

                    //判断流程是否逾期
                    if (cdt > work.SDT && work.WFState == 2 && entStr != "01" && work.RDT != work.SDT) {
                        listbox += "<td><font color=red>逾期</font></td>";
                    }
                    else {
                        listbox += "<td><font color=green>正常</font></td>";
                    }

                    listbox += "<td>" + GetState(work.WFState) + "</td>";

                    listbox += "</tr>";
                }
                if (showRealCount != 0)
                    $('#Table1').append(listbox);
            }
           

            var div = window.parent.document.getElementById("Todolist_EmpWorks");
            if (div != null) {
                div.innerHTML = realCount;
            }

        }
        //查询
        function SearchKey() {
            pageIdex = 1;
            InitPage();
            Paginator(pageCount, pageIdx);
        }

        //分页功能
        function Paginator(pageCount, currentPage) {
            var pageCount = pageCount; //取到pageCount的值(把返回数据转成object类型)
            var options = {
                bootstrapMajorVersion: 3, //版本
                currentPage: currentPage, //当前页数
                totalPages: pageCount, //总页数
                shouldShowPage: true, //是否显示该按钮
                itemTexts: function (type, page, current) {
                    switch (type) {
                        case "first":
                            return "首页";
                        case "prev":
                            return "上一页";
                        case "next":
                            return "下一页";
                        case "last":
                            return "末页";
                        case "page":
                            return page;
                    }
                }, //点击事件，用于通过Ajax来刷新整个list列表
                onPageClicked: function (event, originalEvent, type, page) {
                    pageIdx = page;
                    InitPage(page);
                    $('#page_info').html("").append("<li class='disabled controls'>当前第" + pageIdx + "页，总共" + pageCount +
                            "页,总共" + total + "条记录。</li>");
                }
            };
            $('#page_nav').bootstrapPaginator(options);
            $('#page_info').html("").append("<li class='disabled controls'>当前第" + pageIdx + "页，总共" + pageCount +
                            "页,总共" + total + "条记录。</li>");

        }
        function GetState(wfState) {

            //alert(wfState);

            switch (wfState) {
                case 1:
                    return "草稿";
                case 2:
                    return "待办";
                    break;
                case 3: //已完成.
                    break;
                case 4:
                    return "挂起";
                case 5:
                    return "<font color=red>退回</font>";
                case 6:
                    return "转发";
                case 7:
                    return "删除";
                case 8:
                    return "加签";
                case 11:
                    return "加签回复";
                default:
                    return "其他";
            }
        }
        //获取当前时间
        function getNowFormatDate() {
            var date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            //当前时间=年份-月份-日 小时：分钟
            var cdt = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes();

            return cdt;
        }

        
    </script>
    
</body>
</html>
